/**
 * 事项审批
 */

import request from '@/utils/request'
import { getUser } from '@/utils/auth'

/**
* GET 获取审批列表
* @returns {Promise<Result>}
*/
export function getCheckList(params) {
  const {
    deptCode,
    userId
  } = getUser()
  return request({
    url: '/onm/event/type/getEventCheckList',
    method: 'get',
    params: {
      ...params,
      deptCode,
      userId
    }
  })
}

// /**
// * GET 获取待确认列表
// * @returns {Promise<Result>}
// */
// export function getEventManageList (params) {
//   const {
//     deptCode,
//     userId
//   } = getUser()
//   return request({
//     url: '/event/type/check/getEventManageList',
//     method: 'get',
//     params: {
//       ...params,
//       deptCode,
//       userId
//     }
//   })
// }
/**
* GET 获取待确认列表
* @returns {Promise<Result>}
*/
export function getEventManageList(params) {
  const {
    deptCode,
    userId
  } = getUser()
  return request({
    url: '/onm/event/type/getEventManageList',
    method: 'get',
    params: {
      ...params,
      deptCode,
      userId
    }
  })
}

/**
* GET 获取审批详情
* @returns {Promise<Result>}
*/
export async function getCheckDetail({ id }) {
  return request({
    // url: `/event/type/check/getRules/${id}`,
    url: `/onm/event/type/getItemDetailsInfo?id=${id}`,
    method: 'get'
  })
}

export function getCheckResult(itemCode) {
  return request({
    url: '/event/type/check/getCheckResult',
    method: 'get',
    params: {
      itemCode
    }
  })
}

/**
* GET 获取基础详情
* @returns {Promise<Result>}
*/
export function getBaseDetail({ id }) {
  return request({
    url: `/event/type/check/getEventCheckInfo/${id}`,
    method: 'get'
  })
}
/**
* GET 新版获取基础详情
* @returns {Promise<Result>}
*/
export function getEventCheckInfo({ id }) {
  return request({
    url: `/onm/event/type/getEventCheckInfo?id=${id}`,
    method: 'get'
  })
}

/**
* POST 事项关闭
* @returns {Promise<Result>}
*/
export function eventClose(itemCode, user, cfg) {
  return request({
    url: '/onm/event/type/eventClose',
    method: 'post',
    headers: {
      'Content-Type': 'application/json'
    },
    data: {
      itemCode,
      ...user,
      ...cfg
    }
  })
}

/**
* POST 事项受理
* @returns {Promise<Result>}
*/

export function eventAccept(itemCode, user, cfg) {
  return request({
    // url: '/event/type/check/eventAccept',
    // url: '/event/type/apply/submit',
    url: '/onm/event/type/submit',
    method: 'post',
    headers: {
      'Content-Type': 'application/json'
    },
    data: {
      itemCode,
      ...user,
      ...cfg
    }
  })
}

/**
* POST 协同规则编辑
* @returns {Promise<Result>}
*/
export function eventRuleEdit(data) {
  return request({
    url: '/event/type/check/updateRules',
    method: 'post',
    headers: {
      'Content-Type': 'application/json'
    },
    data
  })
}

/**
* POST 修改事项基本信息(不参与流程状态变更)
* @returns {Promise<Result>}
*/
export function updateItemDetailInfo(data) {
  return request({
    url: '/onm/event/type/updateItemDetailInfo',
    method: 'post',
    headers: {
      'Content-Type': 'application/json'
    },
    data
  })
}

/**
* POST 新增协调记录
* @returns {Promise<Result>}
*/
export function addCoordinateRecord(data) {
  return request({
    url: '/onm/event/type/addCoordinateRecord',
    method: 'post',
    headers: {
      'Content-Type': 'application/json'
    },
    data
  })
}

/**
* POST 新增协同规则
* @returns {Promise<Result>}
*/
export function addItemRules(data) {
  return request({
    url: '/onm/event/type/addItemRules',
    method: 'post',
    headers: {
      'Content-Type': 'application/json'
    },
    data
  })
}

// 变动记录list
export function itemChangeRecordList(params) {
  return request({
    url: `/onm/event/type/item/change/itemChangeRecordList`,
    method: 'get',
    params
  })
}

// 变动记录
export function changeAudit(data) {
  return request({
    url: 'onm/event/type/item/change/audit',
    method: 'post',
    data
  })
}
